package cn.zn.modules.budget.his.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.zn.modules.pz.inter.values.PzConf;
import cn.zn.modules.zzsys.inter.DeptInter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("web/budget/his/budgetinfosum")
public class BudgetInfoSumMvcController {
    @Autowired
    private PzConf pzConf;
    @Autowired
    private DeptInter deptInter;

    /**
     * 预算汇总页面
     *
     * @param model
     */
    @RequestMapping("/budgetSum")
    public void budgetSum(ModelMap model) {
        model.put("initYear", pzConf.getInit().getYear());
        model.put("showDept", deptInter != null);
    }

    /**
     * 部门树
     *
     * @param ap
     * @return
     */
    @GetMapping("/deptTree/{ap}")
    @ResponseBody
    public List<Tree<String>> deptTree(@PathVariable Integer ap) {
        if (deptInter == null) {
            return CollUtil.newArrayList();
        }
        return deptInter.deptTree(ap, null);
    }

}
